package com.eqdd.yiqidian.ui.discover.workdiary;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.coorchice.library.SuperTextView;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.WorkDiaryActivityCustom;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.WorkDiaryBean;
import com.eqdd.yiqidian.box.ItemDecoration.SectionDividerItemDecoration;
import com.eqdd.yiqidian.box.span.NoLineClickSpan;
import com.eqdd.yiqidian.helper.mvchelper.ModelRx2DataSource;
import com.eqdd.yiqidian.helper.mvchelper.Rx2DataSource;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.http.JsonCallBack;
import com.eqdd.yiqidian.http.JsonConverter;
import com.eqdd.yiqidian.ui.InputDialogActivity;
import com.eqdd.yiqidian.ui.mine.UserCardActivity;
import com.eqdd.yiqidian.utils.CopyUtil;
import com.eqdd.yiqidian.utils.DensityUtil;
import com.eqdd.yiqidian.utils.HttpUtil;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.InputDialogFragment;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableResponse;
import com.shizhefei.mvc.MVCSwipeRefreshHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import io.reactivex.Flowable;
import io.rong.imkit.utils.RongDateUtils;

public abstract class BaseWorkDiaryActivity extends BaseActivity {


    public WorkDiaryActivityCustom dataBinding;

    private ArrayList<WorkDiaryBean> workDiaryBeen = new ArrayList<>();
    protected SlimAdapterEx<WorkDiaryBean> slimAdapterEx;
    private MVCSwipeRefreshHelper<List<WorkDiaryBean>> mvcHelper;
    private ModelRx2DataSource<WorkDiaryBean> dataSource;
    private InputDialogFragment inputDialogFragment;
    private int clickedPosition;

    private SlimAdapterEx<WorkDiaryBean.CommentBean> mSlimAdapterEx;
    private String talkTo;
    private SlimAdapterEx<WorkDiaryBean.CommentBean> slimTalkAdapter;
    private boolean isCommentUp;
    private int dealPos;
    private boolean isMyComment;
    private int commentId;
    private String talkContent;
    private int type;
    private MaterialDialog moreDialog;
    private int diaryId;
    private int parentId = 0;
    private String parentUserGuid;
    private int firstCommentId;
    private LayoutInflater inflater;

    abstract String title();

    abstract String getUrl();

    abstract HttpParams getParams();


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        isKeyBoardJustPan = false;
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_work_diary_list);
        inflater = LayoutInflater.from(BaseWorkDiaryActivity.this);
        initTopTitleBar(View.VISIBLE, title());
        initTopRightText("发布", v -> {
            startActivity(WorkDiaryAddActivity.class);
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Config.SUCCESS) {
            switch (requestCode) {
                case Config.INPUT:
                    String content = data.getStringExtra(Config.CONTENT);
                    commentWorkDiary(BaseWorkDiaryActivity.this, diaryId, parentId, content, parentUserGuid, firstCommentId, (commentBean) -> {
                        if (slimTalkAdapter == null) {
                            mSlimAdapterEx.getData().add(0, (WorkDiaryBean.CommentBean) commentBean);
                            mSlimAdapterEx.notifyItemInserted(0);
                        } else if (isCommentUp) {
                            slimTalkAdapter.getData().add(0, (WorkDiaryBean.CommentBean) commentBean);
                            slimTalkAdapter.notifyItemInserted(0);
                        } else {
                            slimTalkAdapter.getData().add((WorkDiaryBean.CommentBean) commentBean);
                            slimTalkAdapter.notifyItemInserted(slimTalkAdapter.getData().size() - 1);
                        }
                        mvcHelper.refresh();
                    });
                    break;


            }
        } else if (resultCode == Config.CHANGE) {
            WorkDiaryBean bean = (WorkDiaryBean) data.getSerializableExtra("bean");
            slimAdapterEx.getData().remove(requestCode);
            slimAdapterEx.getData().add(requestCode, bean);
            slimAdapterEx.notifyItemChanged(requestCode + 1);
        } else if (resultCode == Config.DELETE) {
            slimAdapterEx.getData().remove(requestCode);
            slimAdapterEx.notifyItemRemoved(requestCode + 1);
        }
    }


    @Override
    public void initData() {

        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CHINA);

        dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_work_diary, new SlimInjector<WorkDiaryBean>() {
            @Override
            public void onInject(WorkDiaryBean data, IViewInjector injector) {
                try {
                    injector.gone(R.id.iv_option)
                            .imageCircle(R.id.iv_head, data.getIphoto())
                            .text(R.id.tv_city, data.getLocation())
                            .visibility(R.id.tv_city, TextUtils.isEmpty(data.getLocation()) ? View.GONE : View.VISIBLE)
                            .text(R.id.tv_depart, data.getDepartName() + " " + data.getPostName())
                            .text(R.id.tv_time, RongDateUtils.getConversationFormatDate(sf.parse(data.getCreateTime()).getTime(), BaseWorkDiaryActivity.this))
                            .with(R.id.stv_name, v -> {
                                        SuperTextView superTextView = (SuperTextView) v;
                                        superTextView.setText(data.getStaffName());
                                    }
                            )
                            .text(R.id.tv_diary_content, data.getFeeling())
                            .with(R.id.tv_diary_content, v -> {
                                injector.with(R.id.tv_filling, view -> {
                                    TextView textView = (TextView) view;
                                    buttonBackGround(textView, injector);
                                })
                                        .gone(R.id.layout_diary_content);
                                if (!data.getFeeling().isEmpty()) {
                                    injector.clicked(R.id.tv_filling, view -> {
                                        buttonBackGround((TextView) view, injector);
                                        ((TextView) v).setText(data.getFeeling());
                                        ((TextView) v).setVisibility(View.VISIBLE);
                                        injector.gone(R.id.layout_diary_content);
                                    });
                                }
                                if (!data.getPlan().isEmpty() && data.getPlan().size() > 0) {
                                    injector.visible(R.id.tv_plan);
                                    injector.clicked(R.id.tv_plan, view -> {
                                        buttonBackGround((TextView) view, injector);
                                        v.setVisibility(View.GONE);
                                        setMatter(injector, data.getPlan());
                                    });
                                } else {
                                    injector.gone(R.id.tv_plan);
                                }
                                if (!data.getMatter().isEmpty() && data.getMatter().size() > 0) {
                                    injector.visible(R.id.tv_matter);
                                    injector.clicked(R.id.tv_matter, view -> {
                                        buttonBackGround((TextView) view, injector);
                                        v.setVisibility(View.GONE);
                                        setMatter(injector, data.getMatter());
                                    });
                                } else {
                                    injector.gone(R.id.tv_matter);
                                }
                                if (!data.getTomorrowMatter().isEmpty() && data.getTomorrowMatter().size() > 0) {
                                    injector.visible(R.id.tv_tomorrow_matter);
                                    injector.clicked(R.id.tv_tomorrow_matter, view -> {
                                        buttonBackGround((TextView) view, injector);
                                        v.setVisibility(View.GONE);
                                        setMatter(injector, data.getTomorrowMatter());
                                    });
                                } else {
                                    injector.gone(R.id.tv_tomorrow_matter);
                                }

                            })
                            .with(R.id.stv_support, v -> {
                                SuperTextView superTextView = (SuperTextView) v;
                                superTextView.setText(data.getZanCount() + "");
                                superTextView.setDrawable(getResources().getDrawable(data.isZan() ? R.mipmap.ic_heart_red : R.mipmap.ic_heart_hint));
                            })
                            .with(R.id.stv_msg, v -> {
                                SuperTextView superTextView = (SuperTextView) v;
                                superTextView.setText(data.getCommentCount() + "");
                                superTextView.setDrawable(getResources().getDrawable(R.mipmap.ic_comment));
                            })
                            .clicked(R.id.iv_head, v -> {
                                Bundle bundle = new Bundle();
                                bundle.putString(Config.GUID, data.getCreater());
                                startActivity(UserCardActivity.class, bundle);
                            })
                            .clicked(R.id.stv_msg, v -> {
                                clickedPosition = slimAdapterEx.getData().indexOf(data);
                                openInput(data.getStaffName(), data.getId());
                                //initDialog(data.getId(), data.getStaffName(), injector);
                            })
                            .with(R.id.recyclerView, v -> {
                                initDialog(data.getComment(), data.getId(), (RecyclerView) v);
                            })
                            .visibility(R.id.tv_more_comment, data.getCommentCount() > 3 ? View.VISIBLE : View.GONE)
                            .text(R.id.tv_more_comment, String.format("展开更多%d条评论", data.getCommentCount()))
                            .clicked(R.id.tv_more_comment, v -> {
                                String time = data.getCreateTime();
                                try {
                                    time = RongDateUtils.getConversationFormatDate(sf.parse(data.getCreateTime()).getTime(), BaseWorkDiaryActivity.this);
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }
                                Bundle bundle = new Bundle();
                                bundle.putString(Config.TYPE, "0");
                                bundle.putInt(Config.ID, data.getId());
                                bundle.putString(Config.NAME, data.getStaffName());
                                bundle.putString(Config.PHONE, data.getIphoto());
                                bundle.putString(Config.DEPARTMENT, data.getDepartName() + " " + data.getPostName());
                                bundle.putString(Config.NOW_TIME, time);
                                startActivity(WorkDiaryCommentActivity.class, bundle);
                            });
                            /*.clicked(R.id.iv_option, v -> {
                                String img = null;
                                if (data.getNewImages() != null && data.getNewImages().size() > 0) {
                                    img = data.getNewImages().get(0);
                                }

                                LinkShareBuilder builder = new LinkShareBuilder(BaseWorkDiaryActivity.this);
                                builder.setTitle((data.getMessage() == null || data.getMessage() == "") ? "工作日志" : data.getMessage())
                                        .setId(data.getId() + "")
                                        .setText((data.getMessage() == null || data.getMessage() == "") ? "工作日志" : data.getMessage())
                                        .setUrl(ShareUtil.getWorkCircleUrl(data.getId() + "", ""))
                                        .setImageUrl(img)
                                        .setSource("工作日志")
                                        .setSourceOwner(data.getCreater())
                                        .build();
                                new JShareDialog(builder, BaseWorkDiaryActivity.this).show();
                            });*/
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (!data.isZan()) {
                    injector.enable(R.id.stv_support);
                    injector.clicked(R.id.stv_support, v -> {
                        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.DIARY_ZAN)
                                .params("userGuid", user.getGuid())
                                .params("dailyId", data.getId())
                                .execute(new JsonCallBack<HttpResult>() {
                                    @Override
                                    public void onSuccess(Response<HttpResult> response) {
                                        HttpResult httpResult = response.body();
                                        if (httpResult.getStatus() == 200) {
                                        }
                                    }
                                });
                        SuperTextView superTextView = ((SuperTextView) v);
                        superTextView.setText((data.getZanCount() + 1) + "");
                        superTextView.setDrawable(getResources().getDrawable(R.mipmap.ic_heart_red));
                        data.setZanCount(data.getZanCount() + 1);
                        data.setZan(true);
                        injector.disable(R.id.stv_support);
                        data.getUserZan().add(0, new WorkDiaryBean.UserZanBean(user.getGuid(), user.getIphoto()));
                        ((SlimAdapterEx) ((RecyclerView) injector.findViewById(R.id.recyclerViewHead)).getAdapter()).updateData(data.getUserZan().subList(0, data.getUserZan().size() > 3 ? 3 : data.getUserZan().size()));
                    });
                } else {
                    injector.disable(R.id.stv_support);
                }
                if (((RecyclerView) injector.findViewById(R.id.recyclerViewHead)).getAdapter() == null) {
                    ((RecyclerView) injector.findViewById(R.id.recyclerViewHead)).setLayoutManager(new LinearLayoutManager(BaseWorkDiaryActivity.this, LinearLayoutManager.HORIZONTAL, false));
                    SlimAdapterEx slimAdapterExHead = SlimAdapterEx.create().register(R.layout.list_item_head_img, new SlimInjector<WorkDiaryBean.UserZanBean>() {
                        @Override
                        public void onInject(WorkDiaryBean.UserZanBean data, IViewInjector injector) {
                            injector.with(R.id.iv_head_img, v -> ImageUtil.setCircleImage(data.getHeadImage(), (ImageView) v));
                        }
                    }).attachTo((RecyclerView) injector.findViewById(R.id.recyclerViewHead));
                }
                ItemClickSupport.addTo((RecyclerView) injector.findViewById(R.id.recyclerViewHead))
                        .setOnItemClickListener((recyclerView, position, v) -> {
                            Bundle bundle = new Bundle();
                            bundle.putInt(Config.ID, data.getId());
                            bundle.putString(Config.TYPE, "0");
                            startActivity(WorkDiaryZanListActivity.class, bundle);
                        });
                injector.clicked(R.id.ll_head_img, v -> {
                    Bundle bundle = new Bundle();
                    bundle.putInt(Config.ID, data.getId());
                    bundle.putString(Config.TYPE, "0");
                    startActivity(WorkDiaryZanListActivity.class, bundle);
                });
                ((SlimAdapterEx) ((RecyclerView) injector.findViewById(R.id.recyclerViewHead)).getAdapter()).updateData(data.getUserZan().subList(0, data.getUserZan().size() > 3 ? 3 : data.getUserZan().size()));


            }
        }).attachTo(dataBinding.recyclerView);
        ItemClickSupport.addTo(dataBinding.recyclerView)
                .setOnItemClickListener((recyclerView, position, v) -> {
                    WorkDiaryBean data = slimAdapterEx.getDataItem(position);
                    String time = data.getCreateTime();
                    try {
                        time = RongDateUtils.getConversationFormatDate(sf.parse(data.getCreateTime()).getTime(), BaseWorkDiaryActivity.this);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    Bundle bundle = new Bundle();
                    bundle.putInt(Config.ID, data.getId());
                    bundle.putString(Config.TYPE, "0");
                    bundle.putString(Config.NAME, data.getStaffName());
                    bundle.putString(Config.PHONE, data.getIphoto());
                    bundle.putString(Config.DEPARTMENT, data.getDepartName() + " " + data.getPostName());
                    bundle.putString(Config.NOW_TIME, time);
                    startActivity(WorkDiaryCommentActivity.class, bundle);
                });

        slimAdapterEx.updateData(workDiaryBeen);
        dataSource = new ModelRx2DataSource<>(new ModelRx2DataSource.OnLoadSource() {
            @Override
            public Flowable<List> loadSource(int page, Rx2DataSource.DoneActionRegister register) {
                return OkGo.<HttpResult<List<WorkDiaryBean>>>post(getUrl())
                        .cacheKey(getUrl() + (page == 1 ? 0 : slimAdapterEx.getDataItem(slimAdapterEx.getData().size() - 1).getId()))
                        .cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE)
                        .retryCount(1)
                        .params(getParams())
                        .params("userGuid", user.getGuid())
                        .params("page", page == 1 ? 0 : slimAdapterEx.getDataItem(slimAdapterEx.getData().size() - 1).getId())
                        .converter(new JsonConverter<HttpResult<List<WorkDiaryBean>>>() {
                            @Override
                            public void test() {
                                super.test();
                            }
                        })
                        .adapt(new FlowableResponse<>())
                        .flatMap(httpResultResponse -> Flowable.just(httpResultResponse.body().getItems() == null ? new ArrayList<WorkDiaryBean>() : httpResultResponse.body().getItems()));
            }
        }, 6);
        mvcHelper = new MVCSwipeRefreshHelper<>(dataBinding.swipeRefresh);
        mvcHelper.setNeedCheckNetwork(false);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapterEx);
        mvcHelper.refresh();
    }

    private void setMatter(IViewInjector injector, List<WorkDiaryBean.ItemBean> dataList) {
        injector.visible(R.id.layout_diary_content)
                .with(R.id.layout_diary_content, diaryView -> {
                    ((LinearLayout) diaryView).removeAllViews();
                    for (WorkDiaryBean.ItemBean itemBean : dataList) {
                        View contentView = inflater.inflate(R.layout.list_item_135, null);
                        TextView content = contentView.findViewById(R.id.tv_content);
                        TextView status = contentView.findViewById(R.id.tv_status);
                        TextView time = contentView.findViewById(R.id.tv_time);
                        if (itemBean.getResult() != null && !"".equals(itemBean.getResult())) {
                            status.setText(itemBean.getResult());
                            time.setText(" : " + itemBean.getTimeSlot());
                        } else {
                            status.setVisibility(View.GONE);
                            time.setText(itemBean.getTimeSlot());
                        }
                        content.setText(itemBean.getContent());
                        ((LinearLayout) diaryView).addView(contentView);
                    }
                });
    }


    @Override
    public void setView() {
        initInputDialog();
        dataBinding.llRoot.removeViewAt(0);
        //slimAdapterEx.addHeader(dataBinding.rlHeadRoot);

    }

    private void initInputDialog() {
        inputDialogFragment = new InputDialogFragment();
        inputDialogFragment.setOnClickListener(s -> {
                    commentWorkDiary(BaseWorkDiaryActivity.this, slimAdapterEx.getDataItem(clickedPosition).getId(), 0, s, slimAdapterEx.getDataItem(clickedPosition).getCreater(), 0, object -> {
                        inputDialogFragment.dismiss();
                        WorkDiaryBean dataItem = slimAdapterEx.getDataItem(clickedPosition);
                        dataItem.setCommentCount(dataItem.getCommentCount() + 1);
                        slimAdapterEx.notifyItemChanged(clickedPosition + 1);
                    });
//
                }
        );
    }


    private void initDialog(List<WorkDiaryBean.CommentBean> comment, int id, RecyclerView recyclerView) {
        setRecyclerViewMoveFast(new LinearLayoutManager(this), recyclerView);
        mSlimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_133, new SlimInjector<WorkDiaryBean.CommentBean>() {
            @Override
            public void onInject(WorkDiaryBean.CommentBean data, IViewInjector injector) {
                List<WorkDiaryBean.CommentBean> commentResultBeen;
                if (data.getChildList() != null) {
                    commentResultBeen = data.getChildList();
                } else {
                    commentResultBeen = new ArrayList<>();
                }
                RecyclerView recyclerView = (RecyclerView) injector.findViewById(R.id.recyclerViewCommentComment);

                recyclerView.setLayoutManager(new LinearLayoutManager(BaseWorkDiaryActivity.this));
                SlimAdapterEx<WorkDiaryBean.CommentBean> slimAdapterExCommentChild = SlimAdapterEx.create().register(R.layout.list_item_37, new SlimInjector<WorkDiaryBean.CommentBean>() {
                    @Override
                    public void onInject(WorkDiaryBean.CommentBean data, IViewInjector injector) {
                        injector.with(R.id.tv_comment_comment, view -> {
                            TextView textView = (TextView) view;
                            SpannableString spStr = new SpannableString(data.getCreateStaffName() + ":" + " @" + data.getParentStaffName() + " " + data.getContent());
                            NoLineClickSpan firstSpan = new NoLineClickSpan("#3423ff", v -> {

                                Bundle bundle = new Bundle();
                                bundle.putString(Config.GUID, data.getCreater());
                                startActivity(UserCardActivity.class, bundle);
                            });
                            NoLineClickSpan secondSpan = new NoLineClickSpan("#3423ff", v -> {
                                Bundle bundle = new Bundle();
                                bundle.putString(Config.GUID, data.getParentUserGuid());
                                startActivity(UserCardActivity.class, bundle);
                            });
                            spStr.setSpan(firstSpan, 0, data.getCreateStaffName().length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                            spStr.setSpan(secondSpan, spStr.toString().indexOf("@"), spStr.toString().indexOf("@") + 1 + data.getParentStaffName().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                            textView.setMovementMethod(LinkMovementMethod.getInstance());
                            textView.setText(spStr);
                        });
                    }
                }).attachTo(recyclerView).updateData(commentResultBeen);
                ItemClickSupport.addTo(recyclerView)
                        .setOnItemClickListener((recyclerView1, position, v) -> {
                            WorkDiaryBean.CommentBean dataItem = slimAdapterExCommentChild.getDataItem(position);
                            isMyComment = dataItem.getCreater().equals(AppConstent.user.getGuid());
                            commentId = dataItem.getId();
                            parentId = dataItem.getId();
                            parentUserGuid = dataItem.getCreater();
                            firstCommentId = data.getId();
                            talkTo = dataItem.getCreateStaffName();
                            talkContent = dataItem.getContent();
                            type = 2;
                            slimTalkAdapter = slimAdapterExCommentChild;
                            isCommentUp = false;
                            dealPos = position;
                            showMoreDialog(id);
                        });

                injector.text(R.id.tv_creater, data.getCreateStaffName() + ":")
                        .text(R.id.tv_comment, data.getContent())
                        .clicked(R.id.tv_comment, v -> {
                            isMyComment = data.getCreater().equals(AppConstent.user.getGuid());
                            parentId = data.getId();
                            parentUserGuid = data.getCreater();
                            firstCommentId = data.getId();
                            commentId = data.getId();
                            talkTo = data.getCreateStaffName();
                            talkContent = data.getContent();
                            type = 1;
                            slimTalkAdapter = slimAdapterExCommentChild;
                            isCommentUp = true;
                            dealPos = comment.indexOf(data);
                            mSlimAdapterEx.updateData(comment);
                            showMoreDialog(id);
                        })
                        .clicked(R.id.tv_creater, view -> {
                            Bundle bundle = new Bundle();
                            bundle.putString(Config.GUID, data.getCreater());
                            startActivity(UserCardActivity.class, bundle);
                        });

            }
        }).attachTo(recyclerView).updateData(comment);

    }

    private void openInput(String replyName, int diaryId) {
        this.diaryId = diaryId;
        parentId = 0;
        firstCommentId = 0;
        parentUserGuid = "";
        talkTo = replyName;
        slimTalkAdapter = null;
        talkTo();

    }

    private void showMoreDialog(int id) {
        if (moreDialog == null) {
            ArrayList<Object> objects = new ArrayList<>();
            objects.add("回复");
            objects.add("复制");
            objects.add("删除");
            SlimAdapterEx slimAdapterEx = SlimAdapterEx.create().registerDefault(R.layout.list_item_54, new SlimInjector() {
                @Override
                public void onInject(Object data, IViewInjector injector) {

                    injector.text(R.id.tv_content, (String) data);
                }
            }).updateData(objects);
            moreDialog = new MaterialDialog.Builder(this)
                    .adapter(slimAdapterEx, new LinearLayoutManager(this))
                    .build();
            moreDialog.getRecyclerView().addItemDecoration(new SectionDividerItemDecoration(this)
                    .setHeadHeight(0)
                    .setRightPadding(DensityUtil.percentW(40))
                    .setLeftPadding(DensityUtil.percentW(40))
                    .setLastBootomHeght(0));
            ItemClickSupport.addTo(moreDialog.getRecyclerView())
                    .setOnItemClickListener((recyclerView, position, v) -> {
                        switch (position) {
                            case 0:
                                this.diaryId = id;
                                talkTo();
                                break;
                            case 1:
                                CopyUtil.copy(talkContent);
                                break;
                            case 2:
                                deleteWorkDiaryComment(this, commentId, diaryId, type, () -> {
                                    if (isCommentUp) {
                                        mSlimAdapterEx.getData().remove(dealPos);
                                        mSlimAdapterEx.notifyItemRemoved(dealPos);
                                    } else {
                                        slimTalkAdapter.getData().remove(dealPos);
                                        slimTalkAdapter.notifyItemRemoved(dealPos);
                                    }
                                    mvcHelper.refresh();
                                });
                                break;
                        }
                        moreDialog.dismiss();
                    });
        }
        SlimAdapterEx slimAdapterExMore = (SlimAdapterEx) moreDialog.getRecyclerView().getAdapter();
        if (isMyComment && slimAdapterExMore.getData().size() == 2) {
            slimAdapterExMore.getData().add("删除");
            slimAdapterExMore.notifyItemInserted(2);
        } else if (!isMyComment && slimAdapterExMore.getData().size() == 3) {
            slimAdapterExMore.getData().remove(2);
            slimAdapterExMore.notifyItemRemoved(2);
        }
        moreDialog.show();

    }


    private void setRecyclerViewMoveFast(RecyclerView.LayoutManager layoutManager, RecyclerView recyclerView) {
        recyclerView.setLayoutManager(layoutManager);
        layoutManager.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
    }

    private void talkTo() {
        Bundle bundle = new Bundle();
        bundle.putString(Config.TALK_TO, talkTo);
        startActivityForResult(InputDialogActivity.class, bundle, Config.INPUT);
    }

    private void buttonBackGround(TextView textView, IViewInjector injector) {
        injector.background(R.id.tv_filling, R.drawable.bg_shape_click_gray);
        injector.background(R.id.tv_plan, R.drawable.bg_shape_click_gray);
        injector.background(R.id.tv_matter, R.drawable.bg_shape_click_gray);
        injector.background(R.id.tv_tomorrow_matter, R.drawable.bg_shape_click_gray);
        textView.setBackgroundResource(R.color.gray9);
    }


    public static void commentWorkDiary(BaseActivity baseActivity, int articleId, int parentId, String content, String parentUserGuid, int firstCommentId, HttpUtil.ResultObjectBack resultBack) {
        OkGo.<HttpResult<WorkDiaryBean.CommentBean>>post(HttpConfig.BASE_URL + HttpConfig.DIARY_ADD_COMMIT)
                .params("userGuid", AppConstent.user.getGuid())
                .params("dailyId", articleId)
                .params("parentId", parentId)
                .params("message", content)
                .params("parentUserGuid", parentUserGuid)
                .params("firstCommentId", firstCommentId)
                .execute(new DialogCallBack<HttpResult<WorkDiaryBean.CommentBean>>(baseActivity) {
                    @Override
                    public void onSuccess(Response<HttpResult<WorkDiaryBean.CommentBean>> response) {
                        HttpResult<WorkDiaryBean.CommentBean> httpResult = response.body();
                        // ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            resultBack.onResultBack(httpResult.getItems());
                        }
                    }
                });
    }

    public static void deleteWorkDiaryComment(BaseActivity baseActivity, int commentId, int articleId, int type, HttpUtil.ResultBack resultBack) {
        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.DIARY_DELETE_COMMENT)
                .params("userGuid", AppConstent.user.getGuid())
                .params("commentId", commentId)
                .params("type", type)
                .execute(new DialogCallBack<HttpResult>(baseActivity) {
                    @Override
                    public void onSuccess(Response<HttpResult> response) {
                        HttpResult httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            resultBack.onResultBack();
                        }
                    }
                });
    }


}
